﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Admin.Models.User;
using Zocono.WCS.Application.AppLogManage;
using Zocono.WCS.Application.AppTraces;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;

namespace Zocono.WCS.Admin.Controllers.LogMoudle
{
    public class RunLogController : BaseController
    {
        private readonly LogApp _LogApp;

        public RunLogController(IMemoryCache memoryCache, LogApp logApp, TracesApp tracesApp, IHttpContextAccessor httpContextAccessor) : base(memoryCache, tracesApp, httpContextAccessor)
        {
            _LogApp = logApp;
        }

        public IActionResult Index()
        {
            return View();
        }
        public async Task<ActionResult> RunLogAsync()
        {
            RunLogInfoDto  runLogInfo = new RunLogInfoDto();
            var res = await _LogApp.GetRunLogInfoAsync(runLogInfo);
            return View(res);
        }

        /// <summary>
        /// 获取用户操作列表
        /// </summary>
        /// <returns></returns>
        public async Task<ActionResult> GetRunLogInfoAsync()
        {
            RunLogInfoDto runLogInfo = new RunLogInfoDto();
            runLogInfo.PageIndex = (Start / Length) + 1;
            runLogInfo.PageSize = Length;
            var equipmentCode = Request.Form["EquipmentCode"].ToString();
            var containerBarcode = Request.Form["ContainerBarcode"].ToString();
            var runType = Request.Form["RunType"].ToString();
            var runLog = Request.Form["RunLog"].ToString();
            runLogInfo.EquipmentCode = equipmentCode;
            runLogInfo.RunType = runType;
            runLogInfo.RunLog = runLog;
            runLogInfo.ContainerBarcode = containerBarcode;
            runLogInfo.StarTime = Request.Form["startTime"];
            runLogInfo.EndTime = Request.Form["endTime"];
            var res = await _LogApp.GetRunLogInfoAsync(runLogInfo);
            var pageData = new TableData<RunLogInfoDto>(Draw, res.Total, res.Total, res.Result);
            return Json(pageData);
        }
    }
}
